package com.guosifan.controller;

import com.guosifan.entity.Order;
import com.guosifan.repository.OrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {


    @Autowired
    private OrderRepository orderRepository;

    @PostMapping("/save")
    public void save(@RequestBody Order order){
        orderRepository.save(order);
    }

    @GetMapping("/findByUid/{uid}/{start}/{row}")
    public List<Order> findByUid(@PathVariable("uid")int uid,@PathVariable("start")int start,@PathVariable("row")int row){
        List<Order> uids = orderRepository.findByUid(uid, start, row);
        return uids;
    }

    @GetMapping("findByIdCount/{uid}")
    public int findByIdCount(@PathVariable("uid")int uid){
        int count = orderRepository.findByIdCount(uid);
        return count;
    }

    @GetMapping("/findByState")
    List<Order> findByState(@RequestParam("start") int start,@RequestParam("row") int row){
        List<Order> orders=orderRepository.findByState(start,row);
        return orders;
    }

    @GetMapping("/count")
    int count(){
        int count=orderRepository.count();
        return count;
    }

    @GetMapping("updateState/{id}")
    public void updateState(@PathVariable("id")int id){
        orderRepository.updateState(id);
    }

}
